import Vue from 'vue'
import VueRouter from 'vue-router'
import lazyLoadView from './lazyLoadView'

Vue.use(VueRouter)

const router= new VueRouter({
    routes: [
        { 
            path: '/', 
            component: ()=>lazyLoadView(import('@/pages/HelloWorld.vue')),
            meta: {
                title: '首页'
            }
        },
        { 
            path: '/page1', 
            component: ()=>lazyLoadView(import('@/pages/page1.vue')),
            meta: {
                title: '测试页'
            }
        }
    ]
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router
